package com.college.collegeinfomanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.college.collegeinfomanage.dto.ResearchStrengthDTO;
import com.college.collegeinfomanage.entity.ResearchStrength;
import com.college.collegeinfomanage.service.ResearchStrengthService;
import com.college.collegeinfomanage.util.Result;
import com.college.collegeinfomanage.vo.ResearchStrengthListVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RestController
@RequestMapping("/researchStrength/research")
public class ResearchStrengthController {

    @Resource
    private ResearchStrengthService researchStrengthService;

    @PostMapping("/add")
    public Result add(@RequestBody ResearchStrength researchStrength){
        boolean save = researchStrengthService.save(researchStrength);
        return save ? Result.success("添加成功") : Result.fail("添加失败");
    }

    @GetMapping("/list")
    public Result page(ResearchStrengthDTO researchStrengthDTO){
        IPage<ResearchStrengthListVO> page = researchStrengthService.getPage(researchStrengthDTO);
        return Result.success(page);
    }

    @PutMapping("/update")
    public Result update(@RequestBody ResearchStrength researchStrength){
        boolean b = researchStrengthService.updateById(researchStrength);
        return b ? Result.success("修改成功") : Result.fail("修改失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        boolean b = researchStrengthService.removeById(id);
        return b ? Result.success("删除成功") : Result.fail("删除失败");
    }

}
